package top.chenfu.blog.config.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import top.chenfu.blog.beans.ResponseData;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Auther chenfu
 * @2019/11/1 14:54
 * @Desc
 */
@ControllerAdvice
@Slf4j
public class MyInvocationHandler {

    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public ResponseData errorHandler(Exception e, HttpServletRequest request) {
        log.error("方法出现异常path:{}", request.getServletPath());
        log.error("异常信息e:{}", e);
        return ResponseData.defaultFail("系统错误");
    }

}
